﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.SinhVien
{
    public partial class SinhVien : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                doluoi("0");
            }
        }
        void doluoi(string masv)
        {

            rpt_danhsach.DataSource = mdSinhVien.sinhvien_select(masv);
            rpt_danhsach.DataBind();
        }

       
        protected void cmd_them_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("../Sinhvien/ThemSinhVien.aspx");
        }
        String Xoa()
        {
            if (string.IsNullOrEmpty(Request["xoa"]))
                return "";
            return Request["xoa"].ToString();
        }
        protected void cmd_xoa_Click(object sender, ImageClickEventArgs e)
        {                    
            
            string[] test = null;
            string Mangchon = Xoa();
            char[] c = new char[] { ' ', ',' };
            test = Mangchon.ToString().Split(c);
            int count = 0;
            if (!string.IsNullOrEmpty(Mangchon))
            {
                for (int i = 0; i < test.Length; i++)
                {
                    DataTable dt =  mdSinhVien.sinhvien_delete(test[i]);
                    if(dt.Rows[0]["ErrCode"].ToString() == "0")
                        count++;
                }
                if (count > 0)
                    mdMain.OKBox(this, "Đã xóa được " + count + " dòng dữ liệu.", "/Sinhvien/Sinhvien.aspx");
                else
                    mdMain.OKBox(this, "Xóa dữ liệu thất bại!", "/Sinhvien/Sinhvien.aspx");
            }
        }

        protected void cmd_themexcel_Click(object sender, EventArgs e)
        {
            Response.Redirect("/Sinhvien/ThemSVExcel.aspx");
        }
        
    }
}